<template>
<!-- 保单录入模块-建档资料维护列表页面 -->
    <div class="fillcontain">
        <div class="searchPage">
            <!-- 操作按钮 -->
                <!-- <el-row class="bgfff pt20 pl20"> 
                    <el-col :span="24" class="pt5">
                        <el-button @click="addDialogVisible = true" type="danger" plain>增加</el-button>
                    </el-col>
                </el-row> -->
            <!-- 查询表单 -->
            <el-form :model="searchParams" :rules="rules" ref="ruleForm" label-width="120px" class="search_container" >
                <el-row class="pb20">
                    <el-col :span="6">
                        <el-form-item label="受理号码" prop="applnum">
                            <el-input clearable v-model="searchParams.applnum" @change="changeSearch('applnum')"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="收款凭证号码" prop="wnotnum">
                            <el-input clearable v-model="searchParams.wnotnum" @change="changeSearch('wnotnum')"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="保单号码" prop="chdrnum">
                            <el-input clearable v-model="searchParams.chdrnum" @change="changeSearch('chdrnum')"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" class="text_right">
                        <el-button type="primary" icon="el-icon-search" title="查询(F2)" @click="subGetList"></el-button>
                        <el-button type="primary" plain  icon="el-icon-refresh" @click="resetSearch"></el-button>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <!-- 基本资料页面
        <baseInfo v-if="isSubFlag" ref="imBaseInfo" :formData.sync="formData" @updatIsSubFlag="updatIsSubFlag" @isSubClose="getIsSubClose"></baseInfo> -->

        <!-- 弹窗 增加-->
        <el-dialog
            title="增加"
            :visible.sync="addDialogVisible"
            width="30%"
            center>
        <el-row>
            <el-col :span="24" class="mb15">
                <el-col :span="6" class="common-lab">
                    <label class="labelName">受理号</label>
                </el-col>
                <el-col :span="14" class="common_info">
                    <el-input v-model="addApplnum" clearable placeholder="请输入受理号"></el-input>
                </el-col>
            </el-col>
        </el-row>
        <span slot="footer" class="dialog-footer">
            <!-- <el-button type="primary" @click="addCheckClick">提 交</el-button> -->
            <el-button @click="addDialogVisible = false">返 回</el-button>
        </span>
        </el-dialog>
    </div>
</template>

<script>
    import { mapState, mapGetters } from 'vuex'
    import { getfileInfo,checkReadFiles,addCheck } from "@/api/policyRecord/materialsMaintain/insurance";
    import constant from '@/utils/constant';
	import {getMysqlInfo,getBranchByUserId} from '@/api/setting'
	import  {
	   policyLockStatus
	} from "@/api/underwriting/uw";
    export default {

        data(){
            return {
				organ:'',//登录人员机构号
				mysqlUserInfo:{},//中台数据
                value:'',
                isSubFlag:false,
                addDialogVisible:false,//弹框
                // 查询条件
                rules:{},
                searchParams:{
                    applnum:'', //受理号
                    wnotnum:'',//收款凭证号码
                    chdrnum:'', //保单号
                },
                formData: null,
                addApplnum: null,
                procflgStatus: ''          
            }
        },
        activated(){
            this.$destroyCacheKey();
            document.onkeydown = this.getByF2;
        },    
        created(){
          let userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
          //获取核保员是否是总公司人员
          getMysqlInfo(userInfo.account).then(data =>{
          	this.mysqlUserInfo = data;
          });
		  getBranchByUserId(userInfo.account).then (data => this.organ = data);
        },
        destroyed() {
            document.onkeydown = null;
        },
        mounted(){
            let applnum = this.$route.query.applnum;
            //let procflgStatus = this.$route.query.procflgStatus;
            if(applnum != undefined && applnum != '' && applnum != null){
                this.searchParams.applnum = applnum;
                // if(procflgStatus != undefined && procflgStatus != '' 
                //      && applnum != procflgStatus){
                //     this.procflgStatus = procflgStatus;
                // }
                this.subGetList();
            }
        },
        methods: {
            getByF2(event){
                var e = event || window.event || arguments.callee.caller.arguments[0];
                if (e && e.keyCode == 113) {
                    this.getfileList();
                }
            },
            // 查询列表
           async getfileList(){
                let para = {
                    applnum: this.searchParams.applnum,
                    wnotnum: this.searchParams.wnotnum,
                    chdrnum: this.searchParams.chdrnum,
                    flag: 'Y'
                }
                if(!para.applnum&&!para.wnotnum&&!para.chdrnum){
                    this.$message({
                        message: '请输入一个查询条件来查询！',
                        type: 'error'
                    });
                    return false;
                }
                this.$store.dispatch('loading/CHNAGE_SUBLOADING',true);
              await  checkReadFiles(para).then(res => {
                    if(res.resultCode == constant.SUCCESS){
                        this.canGoJD(res.resultMsg);
                    }
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
                }).catch(err =>{
                    console.log(err);
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
                })
            },
            // 根据条件查询列表
           async subGetList(){
              await  this.getfileList();
            },
		   async canGoJD(applnum) {
			   let userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
				let params = {
				  "applnum":applnum
				}
				await policyLockStatus(params).then( res =>{
					if (res.resultCode == constant.SUCCESS && res.data !=null) {
						let data = res.data;
						//增加机构校验拦截
						if(this.mysqlUserInfo.headStatus != "0") {
							//登录人机构号
							if (userInfo.account != data.checkUserId && this.organ != data.organ) {
								//禁止核保
								this.$message.error('核保员非总公司人员，且本单不是您所属机构的保单，不允许查看 !!');
								return false;
							} 
						}
						if (data.isLock != 'Y') {
							this.$message.error("该受理号处于解锁状态，必须回EUIS操作");
							return;
						} 
						// if (data.isChange && data.isChange == 'Y') {
						// 	this.$message.error("该受理号已在建档页面修改数据并保存，必须从建档页面执行核保操作");
						// 	return;
						// }	
						let flag = 'Y';
						this.$router.push({path:'/home/policyRecord/baseInfo'+'/'+applnum+'/'+flag,query:{
						    pageSource:'jd'
						}});
						}
					})	
			},	
            // 清除查询条件
            resetSearch(){
                this.searchParams.applnum = '';
                this.searchParams.wnotnum = '';
                this.searchParams.chdrnum = '';
            },
            // addCheckClick(){
            //     let para = {
            //         applnum: this.addApplnum,
            //     };
            //     this.$store.dispatch('loading/CHNAGE_SUBLOADING',true);
            //     addCheck(para).then(res => {
            //         if(res.resultCode == constant.SUCCESS){
            //             this.$router.push({path:'/home/policyRecord/baseInfo',query:{
            //                 applnum:res.resultMsg,
            //                 flag:'Y'
            //             }}).catch(data=>{});
            //             this.addApplnum = null;
            //             this.addDialogVisible = false;
            //         }
            //         this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
            //     }).catch(err =>{
            //         console.log(err);
            //         this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
            //     })
            // },
            changeSearch(flag){
                if(flag == 'applnum'){
                    this.searchParams.wnotnum = '';
                    this.searchParams.chdrnum = '';
                }else if(flag == 'wnotnum'){
                    this.searchParams.applnum = '';
                    this.searchParams.chdrnum = '';
                }else if(flag == 'chdrnum'){
                    this.searchParams.applnum = '';
                    this.searchParams.wnotnum = '';
                }
            },
            // 监听是否关闭详情页
            getIsSubClose(e){
                console.log('====:'+e);
                if(e){
                    this.isSubFlag = false;
                } else {
                    this.isSubFlag = true;
                }
            }
        },
        watch: {
            $route(to,from){
                console.log(to);
                console.log(from);
                console.log(this.$route)
            }
        },
    }
</script>

<style lang="less" scoped>
    .fillcontain{
        padding-bottom: 0;
    }
    .contain{
        background: #fff;
        padding: 10px;
        margin-bottom: 20px;
    }
   .pagination{
       padding: 10px 20px;
       text-align: right;
   }
   .operationIcon{
        // padding: 12px;
        border:1px solid #e5e5e5;
        border-radius: 50%;
        width: 22px; 
        height: 22px;
        display: inline-block;
        cursor: pointer;
        box-shadow:0 0 3px #f9f9f9;
        .svg-icon{
            font-size: 14px;
            fill:#68a3fc;
        }
   }
   .search_container{
       padding: 20px 20px 0 20px;
   }
   .toView{
       color: #68a3fc;
       cursor: pointer;
   }

</style>



